// import com.alibaba.druid.sql.ast.SQLDataType;
// import com.alibaba.druid.sql.ast.SQLDataTypeImpl;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.Collections;
// import java.util.List;

#include "SQLFloatExpr.h"
#include "../SQLDataTypeImpl.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/doubleEqual.h"

SQLDataType_ptr SQLFloatExpr::DATA_TYPE = SQLDataType_ptr(new SQLDataTypeImpl(make_string_ptr("FLOAT")));

SQLFloatExpr::SQLFloatExpr()
{
}

SQLFloatExpr::SQLFloatExpr(string_ptr value)
    : SQLNumericLiteralExpr()
{

  this->value = atof(value->c_str());
}

SQLFloatExpr::SQLFloatExpr(double value)
    : SQLNumericLiteralExpr()
{

  this->value = value;
}

SQLObject_ptr SQLFloatExpr::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<SQLFloatExpr>(new SQLFloatExpr(value));
  std::shared_ptr<SQLFloatExpr> x = std::dynamic_pointer_cast<SQLFloatExpr>(clone_tmp);
  // return new SQLFloatExpr(value);
  return x;
}

//@Override
SQLObject_list_ptr SQLFloatExpr::getChildren()
{
  return SQLObject_list_ptr();
}

//@Override
double SQLFloatExpr::getNumber()
{
  return value;
}

double SQLFloatExpr::getValue()
{
  return value;
}

void SQLFloatExpr::setValue(double value)
{
  this->value = value;
}

void SQLFloatExpr::accept0(SQLASTVisitor_ptr visitor)
{
  visitor->visit(SharedObject(SQLFloatExpr));

  visitor->endVisit(SharedObject(SQLFloatExpr));
}

//@Override
bool SQLFloatExpr::equals(Object_ptr o)
{
  if (this == o.get())
  {
    return true;
  }
  if (o == nullptr || getClass() != o->getClass())
  {
    return false;
  }

  std::shared_ptr<SQLFloatExpr> that = std::dynamic_pointer_cast<SQLFloatExpr>(o);

  return doubleEqual::AreEqual(that->value, value);
}

//@Override
int SQLFloatExpr::hashCode()
{
  long temp = long(value);
  return (int)(temp ^ (temp >> 32));
}

//@Override
void SQLFloatExpr::setNumber(double number)
{
  // if (number == null) {
  //     this->setValue(float.NaN);
  //     return;
  // }

  this->setValue(number);
}

//@Override
int SQLFloatExpr::compareTo(std::shared_ptr<SQLFloatExpr> o)
{
  return doubleEqual::AreEqual(value, o->value);
}
